<?php

/*
 * Yanis Framework
 * @copyright Copyright (C) 2011 ch@rlesen. All rights reserved.
 * @license GNU/GPL
 * @author Charles EDOU NZE <charles at charlesen.fr>
 */

/**
 * Database Management
 * 
 * Classe Mysqldb
 *
 */
class Mysqldb {

    /**
     * Multiple database connections are possible
     * Each session is stored in a special variable, active one is maintained
     */
    private $connections = array();

    /**
     * Tells de Database object which connection to use
     * setActiveConnection($id) allows us to change this
     */
    private $activeConnection = 0;

    /**
     * Queries which have been executed and the results cached for later
     * Template Engin ? Maybe
     */
    private $queryCache = array();

    /**
     * Data which has been prepared and then cached for later usage
     * Template Engin ? Maybe
     */
    private $dataCache = array();

    /**
     * Number of queries during execution process
     */
    private $queryCounter = 0;

    /**
     * Record of the last query
     */
    private $lastQuery;

    /**
     * The Registry object
     */
    private $registry;

    /**
     * Construct the Database object
     * @param Registry $registry 
     */
    public function __construct(Registry $registry) {
        $this->registry = $registry;
    }

    /**
     * Create a new database connection
     * @param String database hostname
     * @param String database username
     * @param String password
     * @param String database the current database
     * @return int the id of the new connection
     */
    public function yConnect() {
        /**
         * Create a new instance of the Config Class and start connection
         */
        require_once '../../../config.php';
        $newConnection = new YConfig();
        $this->connections[] = new mysqli($newConnection->host, $newConnection->user, $newConnection->password, $newConnection->db);
        $connection_id = count($this->connections) - 1;
        if (mysql_connect_errno()) {
            trigger_error('Oups! Error connecting to host. ' . $this->connections[$connection_id]->error, E_USER_ERROR);
        }
    }

}

?>